<template>
  <div :class="className" :style="{ height: height, width: width }">
    <h3 class="title">设备CPU占比</h3>
    <el-table :data="data" style="width: 100%" border>
      <el-table-column prop="name" label="设备名"> </el-table-column>
      <el-table-column prop="value" label="CPU占比"> </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { cpuAndMem } from '@/api/homePage'

export default {
  props: {
    className: {
      // type: String,
      // default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '380px'
    }
  },
  data() {
    return {
      data: [],
      data2: []

      //   ,
      //   tableData: [{
      //     name: 'abcde1',
      //     value: '90'
      //   }, {
      //     name: 'abcde2',
      //     value: '80'
      //   }, {
      //     name: 'abcde3',
      //     value: '70'
      //   }, {
      //     name: 'abcde4',
      //     value: '60'
      //   }, {
      //     name: 'abcde5',
      //     value: '50'
      //   }]
    }
  },
  mounted() {
    this.doQuery()
  },
  methods: {
    doQuery() {
      cpuAndMem().then(({ data: { data } }) => {
        // console.log(data)

        data.cpuList.forEach((item, index) => {
          this.data2[index] = {
            value: item.usedCpu + '%',
            name: item.name
          }
        })
        this.data = this.data2
      })
    }
  }
}
</script>
<style scoped>
.title {
  text-align: left;
  padding-left: 11px;
  margin-top: 5px;
  margin-bottom: 20px;
  color: #0691d6;
  font-size: 18px;
  font-family: 'serif';
  font-weight: 540;
}
</style>
